# Contributor: Oleg Titov <oleg.titov@gmail.com>
# Maintainer: Oleg Titov <oleg.titov@gmail.com>
pkgname=singularity
pkgver=3.5.3
pkgrel=0
pkgdesc="Application containers focused on reproducibility for scientific computing and HPC world."
url="https://www.sylabs.io/singularity/"
arch="all !mips !mips64" # fails to build on mips
license="BSD-3-Clause BSD-3-Clause-LBNL"
options="chmod-clean suid !check" # no test suite from upstream
depends="squashfs-tools"
makedepends="
	go
	linux-headers
	binutils-gold
	openssl-dev
	libuuid
	util-linux-dev
	libseccomp-dev
	cryptsetup
	"
subpackages="$pkgname-doc $pkgname-bash-completion:bashcomp:noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/sylabs/singularity/archive/v$pkgver.tar.gz"
builddir="$srcdir/src/github.com/sylabs/$pkgname"

# secfixes:
#   3.5.2-r0:
#     - CVE-2019-19724

prepare() {
	export GOPATH="$srcdir"

	mkdir -p "$(dirname $builddir)"
	mv "$srcdir"/$pkgname-$pkgver "$builddir"/

	echo "$pkgver" > "$builddir"/VERSION
	default_prepare
}

build() {
	export GOPATH="$srcdir"
	export GOBIN="$GOPATH/bin"

	./mconfig \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/infodir \
		--localstatedir=/var

	make -C builddir
}

package() {
	make -C builddir DESTDIR="$pkgdir" install

	install -m644 -D -t "$pkgdir/usr/share/doc/$pkgname" README.md
}

bashcomp() {
	depends=""
	pkgdesc="Bash completion for $pkgname"


	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	mkdir -p "$subpkgdir"/usr/share/bash-completion/completions

	mv "$pkgdir"/etc/bash_completion.d/singularity \
		"$subpkgdir"/usr/share/bash-completion/completions/singularity
}

sha512sums="658f17960730f80bb6d6a2cdfebd565cbe3c5f263d9b8d7a26e84a7a22d9b6970322acb97e851b616a3ef53b88019d54b4677f56f4c29e8e4e484e6e72e170c9  singularity-3.5.3.tar.gz"
